// 导航栏点击效果
const arr = document.querySelectorAll('.content .navbar ul li a');
const navbar = document.querySelector('.navbar');
navbar.addEventListener('click', function (e) {
  if (e.target.tagName === 'A') {
    for (let i = 0; i < arr.length; i++) {
      arr[i].classList.remove('click');
    }
    e.target.className = 'click';
  }
});

// 轮播图
const imgsBox = document.querySelector('.content .swiper ul');
const swiper = document.querySelector('.swiper');
const w = swiper.offsetWidth;
var speed = w;
var index = 0;
setInterval(() => {
  imgsBox.style.transform = `translateX(-${speed}px)`;
  if (speed > 4 * w) {
    imgsBox.style.transition = 'none';
    imgsBox.style.transform = `translateX(0)`;
    speed = w;
  } else {
    imgsBox.style.transition = 'all .3s';
    speed += w;
  }
}, 1000);

// 正在热播
const vBox = document.querySelector('.video-box');

var html = '';
for (let i = 0; i < jsonData.data.length; i++) {
  html += `<div class="video">
  <div class="img-box">
    <img src="${jsonData.data[i].img}" alt="" />
  </div>
  <div class="desc">
    <span class="title">${jsonData.data[i].title}</span>
    <span class="video_content">${jsonData.data[i].desc}</span>
  </div>
</div>`;
}

//返回顶部
var goBack = document.querySelector(".goBack");

var body = document.querySelector("body");

window.addEventListener("scroll",function(){
    
    if(window.pageYOffset >= body.offsetTop+1300){

        goBack.style.display="block";

    }else{

        goBack.style.display="none";

    }

    goBack.addEventListener("click",function(){

        window.scroll(0,0);

    })
})


vBox.innerHTML = html;
